﻿
@{
    ViewBag.Title = "盘点查询";
    Layout = "~/Views/Shared/_Index.cshtml";
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
}

<style>
    #btn_search {
        float: left;
        margin-left: 25px;
        margin-right: 10px;
        width: 45px;
        font-weight: bolder;
    }

    #btn_print {
        width: 45px;
        background-color: #fff;
        color: #00a9ea;
        font-weight: bolder;
        float: left;
    }

    #btn_backIndex {
        float: left;
    }
</style>
<form id="form1">
    <div class="panel panel-default" style="margin-bottom:5px;">
        <div class="panel-heading">查询条件</div>
        <table class="form">
            <tr>
                <th class="formTitle" style="width: 50px;">日期：</th>
                <td class="formValue" colspan="2">
                    <select id="ddlRQ" class="form-control"></select>
                </td>
                <th class="formTitle" style="width: 65px;">关键字：</th>
                <td class="formValue" style="width: 115px;">
                    <input id="txtSRM" type="text" class="form-control" placeholder="拼音 药品名称" />
                </td>
                <th class="formTitle">药品状态：</th>
                <td class="formValue" style="width: 55px;">
                    <select id="ddlYPZT" name="ddlYPZT" class="form-control">
                        <option value="-1">全部</option>
                        <option value="1">启用</option>
                        <option value="0">停用</option>
                    </select>
                </td>
                <th class="formTitle" style="display:none">药品类别：</th>
                <td class="formValue" style="display:none">
                    <select id="ddlYPLB" class="form-control">
                        <option value="">全部</option>
                    </select>
                </td>
                <th class="formTitle">库存显示：</th>
                <td class="formValue">
                    <select id="ddlKCXS" name="ddlKCXS" class="form-control">
                        <option value="-1">全部</option>
                        <option value="0">显示零库存</option>
                        <option value="1">不显示理论数量为零</option>
                        <option value="2">不显示实际数量为零</option>
                        <option value="4">不显示两者都为零</option>
                    </select>
                </td>
                <td class="formValue" style="width: 160px;">
                    <input type="button" id="btn_search" class="btn btn-primary" value="查询" />
                    <input type="button" id="btn_backIndex" class="btn btn-primary" value="返回首页" style="float:right;" />
                </td>
            </tr>
        </table>
    </div>
    <div>
        <table id="gridKCInfoHistory"></table>
        <div id="gridPagerHistory" rel="form1"></div>
    </div>
    <input hidden id="yfbmcode" value="@ViewBag.bmCode">
    <input hidden id="OrganizeId" value="@ViewBag.OrganizeId">
    @Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel
    {
        ShowKeyList = new[] { 10, 6, 9, },
        F10Text = "大类明细",
        F6Text = "剂型明细",
        F9Text = "盘点明细"
    })
</form>
<script language="javascript">
    var $gridKCInfoHistory = $("#gridKCInfoHistory");
    $(function () {
        $("#btn_backIndex").click(function () {//返回
            $.loading("页面跳转中");
            window.location.href = "StockInventoryV3";
        });
        InitialPd();
    });

    //回车事件绑定
    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $("#btn_search").trigger("click");
        }
    });

    //初始化盘点
    function InitialPd() {
        gridKCInfoHistory();
        GetPDSJ();//获取盘点日期
    }

    //库存信息查询
    function gridKCInfoHistory() {
        $gridKCInfoHistory.dataGrid({
            caption: "历史盘点信息",
            postData: getSearchPostData(),
            height: $(window).height() - 220,
            url: "",
            editurl: "clientArray",  //行编辑不向服务器提交数据
            colModel: [
                { label: '药品代码', name: 'ypCode', width: 80, align: 'left' },
                { label: '药品名称', name: 'ypmc', width: 120, align: 'left' },
                { label: '规格', name: 'ypgg', width: 70, align: 'left' },
                { label: '理论数', name: 'llsl', width: 70, align: 'left' },
                { label: '实际数', name: 'sjslstr', width: 70, align: 'left' },
                { label: '数量盈亏', name: 'pdscy', width: 70, align: 'left' },
                { label: '实盘金额', name: 'spje', width: 70, align: 'left' },
                { label: '盘前金额', name: 'pqje', width: 70, align: 'left' },
                { label: '盈亏金额', name: 'ykje', width: 70, align: 'left' },
                { label: '盘点零售价差异', name: 'pdlsjcy', width: 70, align: 'left' },
                { label: '盘点进价差异', name: 'pdpfjcy', width: 70, align: 'left' },
                { label: '批号', name: 'ph', width: 100, align: 'center' },
                { label: '批次', name: 'pc', width: 100, align: 'left' },
                { label: '有效期', name: 'yxq', width: 80, align: 'left' },
                { label: '进价', name: 'jj', width: 60, align: 'left' },
                { label: '零售价', name: 'lsj', width: 60, align: 'left' },
                { label: '进价金额(理)', name: 'llpfje', width: 70, align: 'left' },
                { label: '零售金额(理)', name: 'lllsje', width: 70, align: 'left' },
                { label: '进价金额(实)', name: 'sjpfje', width: 70, align: 'left' },
                { label: '零售金额(实)', name: 'sjlsje', width: 70, align: 'left' },
                { label: '单位', name: 'deptdw', width: 50, align: 'left' },
                { label: '产地', name: 'ycmc', width: 120, align: 'left' },
                { label: '拼音', name: 'py', width: 100, align: 'left' },
                { label: '数量', name: 'deptSjsl', hidden: true },
                { label: '理论数', name: 'llsl_zxbz', hidden: true },
                { label: 'pdmxId', name: 'pdmxId', hidden: true },
                { label: 'zhyz', name: 'zhyz', hidden: true },
                { label: '实际数量(部门包装)', name: 'sjslstr', hidden: true },
                { label: '实际数量(最小单位)', name: 'minSjsl', hidden: true },
                { label: '最小单位', name: 'zxdw', hidden: true },
                { label: 'CreateTime', name: 'CreateTime', hidden: true }
            ],
            gridComplete: function () {
                window.initLayout("MyTabGrid");
            },
            multiselect: false,
            pager: "#gridPagerHistory",
            sortname: 'CreateTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {//绑定查询查询
            $gridKCInfoHistory.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    url: "/PharmacyDrugStorage/SelectInventoryInfoList"
                }).trigger('reloadGrid');
        });
    }

    //查询条件
    function getSearchPostData() {
        var pdsj = $("#ddlRQ").val();
        var pdId = $("#ddlRQ option:selected").attr('data-pdId');
        var srm = $("#txtSRM").val();
        var ypzt = $("#ddlYPZT").val();
        var kcxs = $("#ddlKCXS").val();
        if (!pdsj && !pdId) {
            return false;
        }
        if (kcxs === "" || kcxs == null) {
            kcxs = -1;
        }
        return { pdsj: pdsj, pdId: pdId, srm: srm, ypzt: ypzt, yplb: "", kcxs: kcxs };
    };

    //获取盘点时间
    function GetPDSJ() {
        $.najax({
            type: "GET",
            url: "/PharmacyDrugStorage/GetPDDateDropdownList",
            dataType: "json",
            success: function (ajaxresp) {
                //先清空，再填充
                $("#ddlRQ").empty();
                for (var i = 0; i < ajaxresp.data.length; i++) {
                    $("#ddlRQ").append('<option data-pdId=' + ajaxresp.data[i].pdId + '>' + ajaxresp.data[i].pdsj + '</option>');
                }
                $("#btn_search").trigger("click");
            }
        });
    }

    //大类明细打印
    function newtouch_event_f10() {
        var srm = $("#txtSRM").val();
        var ypzt = $("#ddlYPZT").val();
        var kcxs = $("#ddlKCXS").val();
        var pdId = $("#ddlRQ option:selected").attr('data-pdId');
        var yfbm = $("#yfbmcode").val();
        var OrganizeId = $("#OrganizeId").val();
        var uri = '@reportUrl' + "?tempCode=55" + "&systemCode=" + '@reportSystemCode' + "&hospitalCode=" + OrganizeId + "&srm=" + srm + "&ypzt=" + ypzt + "&kcxs=" + kcxs + "&pdId=" + pdId + "&yfbm=" + yfbm;
        window.open(uri);
        //window.open("/Report/PrintReport?type=StockInventoryDl&param=srm=" + srm + "|ypzt=" + ypzt + "|kcxs=" + kcxs + "|pdId=" + pdId + "|yfbm=" + yfbm + "|OrganizeId=" + OrganizeId, "height=500, width=1195, top=100, left=50, toolbar=no, menubar=no, scrollbar=yes, resizeble=no, location=no, status=no");
    }

    //剂型明细打印
    function newtouch_event_f6() {
        var srm = $("#txtSRM").val();
        var ypzt = $("#ddlYPZT").val();
        var kcxs = $("#ddlKCXS").val();
        var pdId = $("#ddlRQ option:selected").attr('data-pdId');
        var yfbm = $("#yfbmcode").val();
        var OrganizeId = $("#OrganizeId").val();
        var uri = '@reportUrl' + "?tempCode=56" + "&systemCode=" + '@reportSystemCode' + "&hospitalCode=" + OrganizeId + "&srm=" + srm + "&ypzt=" + ypzt + "&kcxs=" + kcxs + "&pdId=" + pdId + "&yfbm=" + yfbm;
        window.open(uri);
        //window.open("/Report/PrintReport?type=StockInventoryJx&param=srm=" + srm + "|ypzt=" + ypzt + "|kcxs=" + kcxs + "|pdId=" + pdId + "|yfbm=" + yfbm + "|OrganizeId=" + OrganizeId, "height=500, width=1195, top=100, left=50, toolbar=no, menubar=no, scrollbar=yes, resizeble=no, location=no, status=no");
    }

    //盘点明细打印
    function newtouch_event_f9() {
        var srm = $("#txtSRM").val();
        var ypzt = $("#ddlYPZT").val();
        var kcxs = $("#ddlKCXS").val();
        var pdId = $("#ddlRQ option:selected").attr('data-pdId');
        var yfbm = $("#yfbmcode").val();
        var OrganizeId = $("#OrganizeId").val();
        var uri = '@reportUrl' + "?tempCode=57" + "&systemCode=" + '@reportSystemCode' + "&hospitalCode=" + OrganizeId + "&srm=" + srm + "&ypzt=" + ypzt + "&kcxs=" + kcxs + "&pdId=" + pdId + "&yfbm=" + yfbm;
        window.open(uri);
        //window.open("/Report/PrintReport?type=StockInventoryV2&param=srm=" + srm + "|ypzt=" + ypzt + "|kcxs=" + kcxs + "|pdId=" + pdId + "|yfbm=" + yfbm + "|OrganizeId=" + OrganizeId, "height=500, width=1195, top=100, left=50, toolbar=no, menubar=no, scrollbar=yes, resizeble=no, location=no, status=no");
    }

</script>